package com.whp.service.impl;

import com.whp.bean.Message;
import com.whp.bean.Person;
import com.whp.service.MessageService;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.Date;

/**
 * @author wanghp
 * @version 1.0
 * @date 2020/07/08 23:41
 */
public class MessageServiceImpl implements MessageService, BeanNameAware, BeanPostProcessor, InitializingBean, Ordered, DisposableBean {
	private Message message;

	private Date date;

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public MessageServiceImpl() {
		//实例化MessageServiceImpl Bean会打印
		System.out.println(" instance MessageServiceImpl Bean");
	}

	public void setMessage(Message message) {
		this.message = message;
	}

	@Override
	public String speak() {
		System.out.println(message);
		return "this is my test -->spring ioc ";
	}

	@Override
	public void setBeanName(String name) {
		System.out.println("BeanNameAware:" + name);
	}

	@Override
	public String toString() {
		return "MessageServiceImpl{" +
				"message=" + message +
				", date=" + date +
				'}';
	}

	public void initMethod() {
		System.out.println("MessageServiceImpl init method() :");
	}

	@Override
	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
		System.out.println("service bean:  :" + "beanName:" + beanName + "postProcessBeforeInitialization");
		return null;
	}

	@Override
	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
		System.out.println("service bean:  :" + "beanName:" + beanName + "postProcessAfterInitialization");
		return null;
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		System.out.println("MessageServiceImpl afterPropertiesSet :");
	}

	@Override
	public int getOrder() {
		return 0;
	}

	@Override
	public void destroy() throws Exception {
		System.out.println("this is destroy");
	}
}
